#include<bits/stdc++.h>
using namespace std;

struct QUEUE
{
	int data;
	QUEUE* next;
};

bool check[100001] = {0, 1};

void insert(QUEUE* &x, int i, int num, int index)
{
	
	QUEUE* r;
	if(index)
	{
		QUEUE* t = x->next;
		while(t->next != NULL && t->data != num)
			t = t->next;
		r = new QUEUE;
		r->data = i;
		r->next = t->next;
		t->next = r;
	}
	else
	{
		QUEUE* t = x;
		while(t->next != NULL && t->next->data != num)
			t = t->next;
		r = new QUEUE;
		r->data = i;
		r->next = t->next;
		t->next = r;
	}
}


void pop(QUEUE* &x, int num)
{
	if(!check[num])
		return ;
	check[num] = 0;
	QUEUE* t = x->next;
	while(t->next != NULL && t->next->data != num)
		t = t->next;
	QUEUE* tt = t->next;
	t->next = tt->next;
	delete tt;
}

void Print(QUEUE* x)
{
	while(x->next != NULL)
	{
		x = x->next;
		cout<<x->data<<" ";
	}
}

int main()
{
	QUEUE* L;
	L = new QUEUE;
	L->next = NULL;
	int n;
	cin>>n;
	QUEUE *r, *t;
	r = L;
	t = new QUEUE;
	t->data = 1;
	r->next = t;
	r = t;
	r->next = NULL;
	int k, p;
	for(int i = 2;i <= n;i++)
	{
		cin>>k>>p;
		check[i] = 1;
		insert(L, i, k, p);
	}
	int m;
	cin>>m;
	for(int i = 1;i <= m;i++)
	{
		int x;
		cin>>x;
		pop(L, x);
	}
	Print(L);
    return 0;
}

